﻿@inherits BaseChartComponent

<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>


@code {
    private IDictionary<string, object> lineStyle = new Dictionary<string, object>();

    private IDictionary<string, object> label = new Dictionary<string, object>();

    private IDictionary<string, object> itemStyle = new Dictionary<string, object>();

    private IDictionary<string, object> checkpointStyle = new Dictionary<string, object>();

    private IDictionary<string, object> controlStyle = new Dictionary<string, object>();

    private IDictionary<string, object> progress = new Dictionary<string, object>();

    private IDictionary<string, object> emphasis = new Dictionary<string, object>();

    private IList<Dictionary<string, object>> datas = new List<Dictionary<string, object>>();

    protected override string ComponentName => "timeline";

    #region 参数

    /// <summary>
    /// 是否显示 timeline 组件。如果设置为false，不会显示，但是功能还存在
    /// </summary>
    [Parameter]
    public bool? show { get; set; }

    /// <summary>
    /// 这个属性目前只支持为 slider，不需要更改
    /// </summary>
    [Parameter]
    public string? type { get; set; }

    /// <summary>
    /// 轴的类型。可选值为：'value' 数值轴，适用于连续数据。'category' 类目轴，适用于离散的类目数据。time' 时间轴，适用于连续的时序数据
    /// </summary>
    [Parameter]
    public string? axisType { get; set; }

    /// <summary>
    /// 表示当前选中项是哪项
    /// </summary>
    [Parameter]
    public int? currentIndex { get; set; }

    /// <summary>
    /// 表示是否自动播放
    /// </summary>
    [Parameter]
    public bool? autoPlay { get; set; }

    /// <summary>
    /// 表示是否反向播放
    /// </summary>
    [Parameter]
    public bool? rewind { get; set; }

    /// <summary>
    /// 表示是否循环播放
    /// </summary>
    [Parameter]
    public bool? loop { get; set; }

    /// <summary>
    /// 表示播放的速度（跳动的间隔），单位毫秒（ms）
    /// </summary>
    [Parameter]
    public int? playInterval { get; set; }

    /// <summary>
    /// 拖动圆点的时候，是否实时更新视图
    /// </summary>
    [Parameter]
    public bool? realtime { get; set; }

    /// <summary>
    /// 合并（merge）策略：默认使用 NORMAL_MERGE。如果 timeline.replaceMerge 被指定了，则使用 REPLACE_MERGE。
    /// </summary>
    [Parameter]
    public dynamic? replaceMerge { get; set; }

    /// <summary>
    /// 表示『播放』按钮的位置。可选值：'left'、'right'
    /// </summary>
    [Parameter]
    public string? controlPosition { get; set; }

    /// <summary>
    /// 所有图形的 zlevel 值
    /// </summary>
    [Parameter]
    public int? zlevel { get; set; }

    /// <summary>
    /// 组件的所有图形的z值。控制图形的前后顺序。z值小的图形会被z值大的图形覆盖
    /// </summary>
    [Parameter]
    public int? z { get; set; }

    /// <summary>
    /// 组件离容器左侧的距离
    /// </summary>
    [Parameter]
    public string? left { get; set; }

    /// <summary>
    /// 组件离容器上侧的距离
    /// </summary>
    [Parameter]
    public string? top { get; set; }

    /// <summary>
    /// 组件离容器右侧的距离
    /// </summary>
    [Parameter]
    public string? right { get; set; }

    /// <summary>
    /// 组件离容器下侧的距离
    /// </summary>
    [Parameter]
    public string? bottom { get; set; }

    /// <summary>
    /// timeline内边距，单位px，默认各方向内边距为5，接受数组分别设定上右下左边距
    /// </summary>
    [Parameter]
    public dynamic? padding { get; set; }

    /// <summary>
    /// 摆放方式，可选值有：'vertical'：竖直放置。'horizontal'：水平放置
    /// </summary>
    [Parameter]
    public string? orient { get; set; }

    /// <summary>
    /// 是否反向放置 timeline，反向则首位颠倒过来
    /// </summary>
    [Parameter]
    public bool? inverse { get; set; }

    /// <summary>
    /// timeline标记的图形
    /// </summary>
    [Parameter]
    public string? symbol { get; set; }

    /// <summary>
    /// timeline标记的大小
    /// </summary>
    [Parameter]
    public dynamic? symbolSize { get; set; }

    /// <summary>
    /// timeline标记的旋转角度（而非弧度）。正值表示逆时针旋转
    /// </summary>
    [Parameter]
    public float? symbolRotate { get; set; }

    /// <summary>
    /// 如果 symbol 是 path:// 的形式，是否在缩放时保持该图形的长宽比
    /// </summary>
    [Parameter]
    public bool? symbolKeepAspect { get; set; }

    /// <summary>
    /// timeline标记相对于原本位置的偏移
    /// </summary>
    [Parameter]
    public object[]? symbolOffset { get; set; }

    [Parameter]
    public object[]? data { get; set; }

    #endregion

    protected override Task SetParametersAsync()
    {
        if (show.HasValue)
            FillSetting("show", show.Value);

        if (!string.IsNullOrEmpty(type))
            FillSetting("type", type);

        if (!string.IsNullOrEmpty(axisType))
            FillSetting("axisType", axisType);

        if (currentIndex.HasValue)
            FillSetting("currentIndex", currentIndex.Value);

        if (autoPlay.HasValue)
            FillSetting("autoPlay", autoPlay.Value);

        if (rewind.HasValue)
            FillSetting("rewind", rewind.Value);

        if (loop.HasValue)
            FillSetting("loop", loop.Value);

        if (playInterval.HasValue)
            FillSetting("playInterval", playInterval.Value);

        if (realtime.HasValue)
            FillSetting("realtime", realtime.Value);

        if (replaceMerge != null)
            FillSetting("replaceMerge", replaceMerge);

        if (!string.IsNullOrEmpty(controlPosition))
            FillSetting("controlPosition", controlPosition);

        if (zlevel.HasValue)
            FillSetting("zlevel", zlevel.Value);

        if (z.HasValue)
            FillSetting("z", z.Value);

        if (!string.IsNullOrEmpty(left))
            FillSetting("left", left);

        if (!string.IsNullOrEmpty(top))
            FillSetting("top", top);

        if (!string.IsNullOrEmpty(right))
            FillSetting("right", right);

        if (!string.IsNullOrEmpty(bottom))
            FillSetting("bottom", bottom);

        if (padding != null)
            FillSetting("padding", padding);

        if (!string.IsNullOrEmpty(orient))
            FillSetting("orient", orient);

        if (inverse.HasValue)
            FillSetting("inverse", inverse.Value);

        if (!string.IsNullOrEmpty(symbol))
            FillSetting("symbol", symbol);

        if (symbolSize != null)
            FillSetting("symbolSize", symbolSize);

        if (symbolRotate.HasValue)
            FillSetting("symbolRotate", symbolRotate.Value);

        if (symbolKeepAspect.HasValue)
            FillSetting("symbolKeepAspect", symbolKeepAspect.Value);

        if (symbolOffset != null && symbolOffset.Length > 0)
            FillSetting("symbolOffset", symbolOffset);

        if (data != null && data.Length > 0)
            FillSetting("data", data);

        return Task.CompletedTask;
    }

    public void SetLineStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("lineStyle", lineStyle);
        action?.Invoke(lineStyle);
    }

    public void SetLabel(Action<IDictionary<string, object>> action)
    {
        FillSetting("label", label);
        action?.Invoke(label);
    }

    public void SetItemStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("itemStyle", itemStyle);
        action?.Invoke(itemStyle);
    }

    public void SetCheckpointStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("checkpointStyle", checkpointStyle);
        action?.Invoke(checkpointStyle);
    }

    public void SetControlStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("controlStyle", controlStyle);
        action?.Invoke(controlStyle);
    }

    public void SetProgress(Action<IDictionary<string, object>> action)
    {
        FillSetting("progress", progress);
        action?.Invoke(progress);
    }

    public void SetEmphasis(Action<IDictionary<string, object>> action)
    {
        FillSetting("emphasis", emphasis);
        action?.Invoke(emphasis);
    }

    public void SetDatas(Action<IList<Dictionary<string, object>>> action)
    {
        FillSetting("data", datas);
        action?.Invoke(datas);
    }

    public void RemoveDatas(Dictionary<string, object> item)
    {
        if (datas.Contains(item))
            datas.Remove(item);
    }
}
